//
//  PublishSelectViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/11.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "PublishSelectViewController.h"
#import "PublistMessageViewController.h"
#import "RentVieitor.h"
#import "PublishOfficeViewController.h"
#import "PublishStore ViewController.h"

@interface PublishSelectViewController () {
    
    NSInteger index;
}

@end

@implementation PublishSelectViewController

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"经纪人认证";
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];
    
}

- (void)creatLeftView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 120)];
    headView.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
    [self.view addSubview:headView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, KWidth-200, 40)];
    label.text = @"发布租房信息";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:17];
    label.textColor = [UIColor whiteColor];
    [headView addSubview:label];
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 20+12, 100,30);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 10, 90)];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateHighlighted];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:leftBtn];
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(KWidth-65, 20+10, 50, 20);
    [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:rightBtn];
    
    UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, KWidth, KWidth*94/780)];
    imgview.image = [UIImage imageNamed:@"publish1"];
    [headView addSubview:imgview];
    
    UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 140, KWidth, 20)];
    firstLabel.text = @"第一步  选择类别";
    firstLabel.textAlignment = NSTextAlignmentCenter;
    firstLabel.font = [UIFont systemFontOfSize:17];
    firstLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    [self.view addSubview:firstLabel];
    
    UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 170, KWidth, 13)];
    secondLabel.text = @"请选择你当前发布的租房信息类别";
    secondLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.font = [UIFont systemFontOfSize:13];
    secondLabel.textColor = [Utils colorConvertFromString:@"#666666"];
    [self.view addSubview:secondLabel];
    
    //155 170
    
    NSArray *imgArray = @[@"pub-住宅",@"pub-写字楼",@"pub-商铺"];
    NSArray *titltArray = @[@"住宅",@"写字间",@"商铺"];
    CGFloat width = (KWidth-65-35)/2;
    CGFloat hight = width*170/150;
    CGFloat margin = 35/2;
    
    for (int i=0; i<imgArray.count; i++) {
        
        UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(15+(margin)*(1+i%2)+width*(i%2), 170+13+(margin)*(i/2+1)+hight*(i/2), width, hight)];
        control.tag = 100+i;
        control.backgroundColor = [UIColor whiteColor];
        control.layer.masksToBounds = YES;
        control.layer.cornerRadius = 3;
        [control addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:control];
        
        UIImageView * imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake((width-80)/2, 25, 80, 80)];
        imgView2.layer.masksToBounds = YES;
        imgView2.tag = 300+i;
        imgView2.layer.cornerRadius = 80/2;
        imgView2.backgroundColor = [Utils colorConvertFromString:@"#dfdfdf"];
        [control addSubview:imgView2];
        
        UIImageView *imgView3 = [[UIImageView alloc] init];
        imgView3.image = [UIImage imageNamed:imgArray[i]];
        imgView3.frame = CGRectMake(40/2, 40/2, 40, 40);
        [imgView2 addSubview:imgView3];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, hight-20-35/2, width,20 )];
        label.text = titltArray[i];
        label.tag = 200+i;
        label.textColor = [Utils colorConvertFromString:@"#dfdfdf"];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:17];
        [control addSubview:label];
        
        if (i == 0) {
            
           label.textColor = [Utils colorConvertFromString:@"#1fae0c"];
           imgView2.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
        }
        
    }

}

- (void)clickAction:(UIControl *)control {
    
    index = control.tag - 100;
    for (int i=0; i<3; i++) {
        
        UIControl *control = (UIControl *)[self.view viewWithTag:100+i];
        UILabel *label = (UILabel *)[control viewWithTag:200+i];
        UIImageView *imgView = (UIImageView *)[control viewWithTag:300+i];
        label.textColor = [Utils colorConvertFromString:@"#dfdfdf"];
        imgView.backgroundColor = [Utils colorConvertFromString:@"#dfdfdf"];
    }
    
    UILabel *label = (UILabel *)[control viewWithTag:control.tag+100];
    UIImageView *imgView = (UIImageView *)[control viewWithTag:control.tag+200];
    label.textColor = [Utils colorConvertFromString:@"#1fae0c"];
    imgView.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)nextAction {
    
    if (index == 0) {
        
        PublistMessageViewController *pubvc = [[PublistMessageViewController alloc] init];
        [self.navigationController pushViewController:pubvc animated:YES];
        return;
    }
    
    if (index == 1) {
        
        PublishOfficeViewController *pubvc = [[PublishOfficeViewController alloc] init];
        [self.navigationController pushViewController:pubvc animated:YES];
        return;
    }
    
    if (index == 2) {
        PublishStore_ViewController *storeVc = [[PublishStore_ViewController alloc] init];
        [self.navigationController pushViewController:storeVc animated:YES];
    }
    
    
}

@end
